/**
 * DLA/Oscilloscope Project Software
 * 
 * By Kevin Cuzner <kevincuzner@yahoo.com>
 * 
 * This file is part of the DLA/Oscilloscope Project Software.
 *
 * The DLA/Oscilloscope Project Software is free software: you can 
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * The DLA/Oscilloscope Project Software is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with The DLA/Oscilloscope Project Software.
 * If not, see <http://www.gnu.org/licenses/>.
 */

using System;

namespace DLAOscilloscopegtk
{
	/**
	 * Sample Class. Encapsulates a single sample, whether in DLA mode or Oscilloscope mode
	 */
	public class Sample
	{
		/**
		 * Contains the data for the sample
		 */
		protected ulong val;
		/**
		 * The length of the sample
		 */
		protected uint size;
		/**
		 * The width in bits for this sample
		 */
		protected uint width;
		
		/**
		 * Constructor for the Sample
		 * @param data the data to use for this sample
		 * @param size the length in bytes of the sample
		 * @param width the width in bits of the sample
		 */
		public Sample (byte[] data, uint size, uint width)
		{
			//check the constructor arguments
			if (size > 4)
				throw new ArgumentOutOfRangeException ("size", "Size must be less than 4 bytes");
			if (size < 1)
				throw new ArgumentOutOfRangeException ("size", "Size must be greater than 0");
			
			//assemble the data bytes
			this.val = 0;
			for (uint i = 0; i < size; i++) {
				this.val <<= 8;
				this.val |= data [i];
			}
			
			this.size = size;
			this.width = width;
		}
		
		/**
		 * Attribute to access the read-only value
		 */
		public ulong Value {
			get {
				return val;
			}
		}
		
		/**
		 * Attribute to access the read-only sample length
		 */
		public uint Size {
			get { return size; }
		}
		
		/**
		 * Attribute to access the read-only sample width in bits
		 */
		public uint Width {
			get {
				return width;
			}
		}
	}
}

